Imports System.Data
Partial Class Admin_frmTabCategory
    Inherits System.Web.UI.Page
    Dim conn As New SqlString()
    Dim _BO As New Bo()
    Dim _CategoryVO As New CategoryVo()
    Dim _EmployeeId As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _EmployeeId = Session("EmpId")
        If _EmployeeId = "" Then
            Response.Redirect("../Client/frmLogin.aspx")
        End If
        If Not Page.IsPostBack Then
            panel2.Visible = False
            panel4.Visible = False
            GridData()
        End If
    End Sub
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Try
            _CategoryVO.CategoryId = txtCategoryId.Text
            _CategoryVO.CategoryName = txtCategoryName.Text
            _BO.InsertCategory(_CategoryVO)
            ClearAll()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Public Sub ClearAll()
        txtCategoryId.Text = ""
        txtCategoryName.Text = ""
        MsgBox("Category inserted")
    End Sub
    Sub GridData()
        Dim dtCategory As DataTable
        dtCategory = _BO.getcategoryDetails()
        gdCategory.DataSource = dtCategory
        gdCategory.DataBind()
    End Sub
    Protected Sub gdCategory_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles gdCategory.EditCommand
        Session("EmpId") = _EmployeeId
        Response.Redirect("frmModifyCategory.aspx?CategoryName=" & e.Item.Cells(0).Text)
    End Sub
    Protected Sub gdCategory_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles gdCategory.DeleteCommand
        _BO.DeleteCategory(e.Item.Cells(0).Text)
        GridData()
    End Sub
    Protected Sub ImageAdd_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageAdd.Click
        panel2.Visible = True
        panel4.Visible = False
    End Sub

    Protected Sub ImageEdit_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageEdit.Click
        panel2.Visible = False
        panel4.Visible = True
        GridData()
    End Sub

    Protected Sub gdCategory_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles gdCategory.PageIndexChanged
        gdCategory.CurrentPageIndex = e.NewPageIndex
        GridData()
    End Sub

    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
        txtCategoryId.Text = ""
        txtCategoryName.Text = ""
    End Sub
End Class
